package com.tanhua.sso.controller;

import com.tanhua.sso.service.SmsService;
import lombok.extern.log4j.Log4j;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;


@RestController
@RequestMapping("user")
@Slf4j
public class SmsController {

    @Autowired
    private SmsService smsService;

    @PostMapping("/login")
    public String login(@RequestBody Map<String,String> param){
        //获取手机号
        String phone = param.get("phone");
        boolean isExist = smsService.checkPhone(phone);
        //判断是否存在，不存在再发送验证码进行注册
        String resule =null;
        if (isExist){
            return "用户已存在";
        }else {
            resule = smsService.sendMsg(phone);
        }
        log.info("向"+phone+"发送短信" +resule );
        return "xxxx";
    }
}
